package thinkinjava4.util;

import java.util.Random;

public class Enums {
    private static Random random = new Random(47);

    /**
     * <T extends Enum<T>>表示T是一个enum实例
     *
     * @param ec
     * @param <T>
     * @return
     * @see
     */
    public static <T extends Enum<T>> T random(Class<T> ec) {
        return random(ec.getEnumConstants());
    }

    public static <T> T random(T[] values) {
        return values[random.nextInt(values.length)];
    }
}
